//
//  TLLabel.m
//  TLUIKit
//
//  Created by c on 2021/11/3.
//

#import "TLLabel.h"

@implementation TLLabel

- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        self.preferredMaxLayoutWidth = self.frame.size.width - self.edgeInsets.left - self.edgeInsets.right;
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.preferredMaxLayoutWidth = self.frame.size.width - self.edgeInsets.left - self.edgeInsets.right;
    }
    return self;
}

- (void)drawTextInRect:(CGRect)rect {
    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}

- (CGSize)intrinsicContentSize {
    CGSize size = [super intrinsicContentSize];
    size.width += (self.edgeInsets.left + self.edgeInsets.right);
    size.height += (self.edgeInsets.top + self.edgeInsets.bottom);
    return size;
}

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = [super sizeThatFits:size];
    newSize.width = size.width + self.edgeInsets.left + self.edgeInsets.right;
    newSize.height = size.height + self.edgeInsets.top + self.edgeInsets.bottom;
    return newSize;
}

- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets {
    self.preferredMaxLayoutWidth = self.frame.size.width - edgeInsets.left - edgeInsets.right;
}

@end
